home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / 3D & Offscreen for MacApp 3 / 3D & Offscreen Sample.sea / 3D & Offscreen Sample / TOffscreenAdorner.cp < prev    next >
Text File  |  1993-05-10  |  6KB  |  162 lines

  1. /*************************************************************************
  2.  
  3.         File: TOffscreenAdorner.h
  4.  
  5.         C O P Y R I G H T    N O T I C E
  6.  
  7.          Copyright ⌐ 1993 Eric Hanig.
  8.         All Rights Reserved.
  9.         No portions of this source code or the resulting compiled
  10.         program may be used without express written consent and liscensing
  11.         by Eric Hanig, Inc.
  12.  
  13.  
  14.         D E S C R I P T I O N
  15.  
  16.  
  17.         Classes Defined Here:
  18.  
  19.              Ñ
  20.  
  21.  
  22.      Change History
  23.  
  24.         Rev 1    Tue, Apr 13, 1993 @ 4:59 PM        Hanig
  25.             Creation
  26.  
  27.  *************************************************************************/
  28. /*************************************************************************/
  29. /*                            Include Files                                 */
  30. /*************************************************************************/
  31. #ifndef        __TOffscreenAdorner__
  32. #include    "TOffscreenAdorner.h"
  33. #endif
  34.  
  35. /*************************************************************************/
  36. /*                                Constants                                     */
  37. /*************************************************************************/
  38.  
  39. /*************************************************************************/
  40. TOffscreenAdorner::TOffscreenAdorner( void )
  41. {
  42.  
  43. }
  44.  
  45. /*************************************************************************/
  46. #pragma segment MAAdornerNonRes
  47. // This method is how the adorner is told which view to attach the TOffscreenDrawEnvironment
  48. // to. Since this method is not called by the view instansiation with resources,
  49. // we must add the adorner procedurally.
  50. pascal void TOffscreenAdorner::AddedToView(TView* itsView)
  51. {
  52.     inherited::AddedToView (itsView);
  53.     
  54.     // Get rid of old if exists
  55.     fOldDrawingEnvironment = (TDrawingEnvironment *)FreeIfObject(fOldDrawingEnvironment);
  56.     
  57.     // save old drawing env in case later we don't want it
  58.     // Note we must Clone it (by hand) because TViews SetDrawingEnvironment
  59.     // will dispose of the object.
  60.     TDrawingEnvironment* tempDrawingEnvironment = itsView->GetDrawingEnvironment ();
  61.     if ( tempDrawingEnvironment )
  62.     {
  63.         TDrawingEnvironment* fOldDrawingEnvironment = new TDrawingEnvironment;
  64.         fOldDrawingEnvironment->fBackgroundColor    = tempDrawingEnvironment->fBackgroundColor;
  65.         fOldDrawingEnvironment->fForegroundColor    = tempDrawingEnvironment->fForegroundColor;
  66.         fOldDrawingEnvironment->fPenMode            = tempDrawingEnvironment->fPenMode;
  67.         fOldDrawingEnvironment->fPenPattern            = tempDrawingEnvironment->fPenPattern;
  68.         fOldDrawingEnvironment->fPenSize            = tempDrawingEnvironment->fPenSize;
  69.         fOldDrawingEnvironment->fSavedBackgroundColor = tempDrawingEnvironment->fSavedBackgroundColor;
  70.         fOldDrawingEnvironment->fSavedForegroundColor = tempDrawingEnvironment->fSavedForegroundColor;
  71.         fOldDrawingEnvironment->fSavedPenState        = tempDrawingEnvironment->fSavedPenState;
  72.     }
  73.     
  74.     // Create a new offscreen one, and make sure it contains old setup
  75.     TOffscreenDrawEnvironment * aDrawingEnvironment = new TOffscreenDrawEnvironment;
  76.     aDrawingEnvironment->IOffscreenDrawEnvironment (fOldDrawingEnvironment, fUseGlobalGWorld);
  77.  
  78.     fOffscreenDrawingEnvironment = aDrawingEnvironment;
  79.     
  80.     // tell TOffscreenDrawEnvironment which view to use
  81.     fOffscreenDrawingEnvironment->AttachView(itsView);
  82.     
  83.     // tell view to use TOffscreenDrawEnvironment instead of normal one
  84.     itsView->SetDrawingEnvironment (fOffscreenDrawingEnvironment, true);
  85. }
  86.  
  87.  
  88. /*************************************************************************/
  89. #pragma segment MAAdornerNonRes
  90. // call if you no longer want to use the TOffscreenDrawEnvironment for this view.
  91. // The view will go back to using the old (if any) drawing environment.
  92. pascal void TOffscreenAdorner::RemovedFromView(TView* itsView)
  93. {
  94.     // destroy offscreen env, and set old
  95.     itsView->SetDrawingEnvironment (fOldDrawingEnvironment, true);
  96.     
  97.     fOffscreenDrawingEnvironment = NULL;
  98.     
  99.     inherited::RemovedFromView (itsView);
  100. }
  101.  
  102.  
  103. /*************************************************************************/
  104. #pragma segment MAAdornerNonRes
  105. // Make sure the offscreen changes size when the view does.
  106. pascal void TOffscreenAdorner::ViewChangedFrame (TView* itsView,
  107.                                             const VRect& oldFrame,
  108.                                             const VRect& newFrame,
  109.                                             Boolean    invalidate)
  110. {
  111.     inherited::ViewChangedFrame (itsView, oldFrame, newFrame, invalidate);
  112.     
  113.     if (fOffscreenDrawingEnvironment)
  114.         fOffscreenDrawingEnvironment->UpdateOffscreen();
  115. }
  116.  
  117.  
  118. /*************************************************************************/
  119. #pragma segment MAAdornerNonRes
  120. // This adorner does no drawing, only attaches a TOffscreenDrawEnvironment
  121. // to a view, and then it's done.
  122. pascal Boolean TOffscreenAdorner::DoesAdorn (TView* /*itsView*/)
  123. {
  124.     return false;    // this adorner really doesn't do anything, so don't draw
  125. }
  126.  
  127.  
  128. /*************************************************************************/
  129. #pragma segment MAAdornerNonRes
  130. pascal void TOffscreenAdorner::Initialize()
  131. {
  132.     inherited::Initialize();
  133.  
  134.     fOldDrawingEnvironment = NULL;
  135.     fOffscreenDrawingEnvironment = NULL;
  136. }
  137.  
  138.  
  139. /*************************************************************************/
  140. #pragma segment MAAdornerNonRes
  141. pascal void TOffscreenAdorner::Free()
  142. {
  143.     FreeIfObject(fOffscreenDrawingEnvironment);
  144.     FreeIfObject(fOldDrawingEnvironment);
  145.     
  146.     inherited::Free();
  147. }
  148.  
  149. /*************************************************************************/
  150. #pragma segment MAAdornerNonRes
  151. pascal void TOffscreenAdorner::IOffscreenAdorner(IDType itsID, Boolean freeOnDeletion, Boolean useGlobalGWorld)
  152. {
  153.     this->IAdorner (itsID, freeOnDeletion );
  154.     
  155.     fUseGlobalGWorld = useGlobalGWorld;
  156. }
  157.  
  158.  
  159.  
  160. /*************************************************************************/
  161. /*************************************************************************/
  162.